﻿Imports System.Collections.Generic
Imports System.Security.Claims
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI

Partial Public Class Login
    Inherits Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        RegisterHyperLink.NavigateUrl = "Register"
        OpenAuthLogin.ReturnUrl = Request.QueryString("ReturnUrl")

        Dim returnUrl = HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))
        If Not [String].IsNullOrEmpty(returnUrl) Then
            RegisterHyperLink.NavigateUrl += "?ReturnUrl=" & Convert.ToString(returnUrl)
        End If
    End Sub

    Protected Sub LogIn(sender As Object, e As EventArgs)
        If IsValid Then
            ' Validate the user password
            If IdentityConfig.Secrets.Validate(UserName.Text, Password.Text) Then
                Dim localUserId As String = IdentityConfig.Logins.GetUserId(IdentityConfig.LocalLoginProvider, UserName.Text)
                If localUserId IsNot Nothing Then
                    Context.SignIn(localUserId, New Claim() {}, RememberMe.Checked)
                    IdentityConfig.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
                End If


            Else
                FailureText.Text = "Your login attempt was not successful. Please try again."
            End If
        End If
    End Sub
End Class
